package books

class Book {
    String title
    String author
    String description
    String ISBN
    int minimumGradeLevel
    int maximumGradeLevel
    String language
    String category

    static constraints = {
        title(blank:false)
        author(blank:false)
        description(maxSize:255)
        ISBN(size:13..13, matches: '(?=[-0-9xX ]{13}$)(?:[0-9]+[- ]){3}[0-9]*[xX0-9]$')
        minimumGradeLevel(inList:0..6)
        maximumGradeLevel(inList:0..6, 
            validator: {max, book -> return max>book.minimumGradeLevel})
        language(blank:false)
        category(blank:false, inList:['General Leisure Reading', 'Reading Skills',
            'Math Skills', 'Health', 'Science'])
    }
}
